#include "systemdata.h"
#include "stdio.h"
char bank0[FMC_FLASH_SECTION_SIZE] = {0xff};
char bank1[FMC_FLASH_SECTION_SIZE] = {0xff};
int FLASH_BANK_1=0;
int FLASH_BANK_2=1;
S_SYSTEM_DATA tmp;
static void loaddb(char *pbuff, char *filename)
{
	FILE * f = fopen(filename, "rb");
	if(!f)
	{
		memset(pbuff, 0xff, FMC_FLASH_SECTION_SIZE);
		f = fopen(filename, "wb");
		fwrite(pbuff, 1, FMC_FLASH_SECTION_SIZE, f);
		fclose(f);
		return ;
	}
	fread(pbuff, 1, FMC_FLASH_SECTION_SIZE, f);
	fclose(f);
}
static void saveDb(char *pbuff, char *filename)
{
	FILE * f = fopen(filename, "wb");
	fwrite(pbuff, 1, FMC_FLASH_SECTION_SIZE, f);
	fclose(f);
}
void saveall()
{
	saveDb(bank0, "bank0.db");
	saveDb(bank1, "bank1.db");
}
int main(int argc, char **argv)
{
	loaddb(bank0, "bank0.db");
	loaddb(bank1, "bank1.db");
	printf("systemData Size %d\n", sizeof(S_SYSTEM_DATA));
	systemData_init();
	int id = 1;
	int preid = atoi(gSystemData.id);
	for(;id<1000000;id++)
	{
		sprintf(gSystemData.id, "%d", preid  + id);
		systemData_save(&gSystemData);

		rtyReadFromFlash(&tmp, sizeof(S_SYSTEM_DATA));
		SYSTEM_DB_DEBUG("load systemData id:%s", tmp.id);
	}	
	
	return 0;
}
